package fanshe;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
//javabean一定要有无参构造
public class diaoyong {
	public static void main(String[] args) throws Exception{
		//动态操作构造器
		String path="fanshe.user";
		try {
			Class<user> c=(Class<user>) Class.forName(path);
			user user=c.newInstance();//调用了user的无参构造
			System.out.println(user);
			Constructor k=c.getDeclaredConstructor(int.class,int.class,String.class);
			user u=(fanshe.user) k.newInstance(100,100,"ajhfgsg");
			System.out.println(u.getUname());
			user u0=c.newInstance();
//			u0.setUname("as");
			Method m=c.getDeclaredMethod("setUname",String.class);
			m.invoke(u0, "slakeedh");
			System.out.println(u0.getUname());
			user u3=c.newInstance();
			Field f=c.getDeclaredField("age");
			f.setAccessible(true);
			f.set(u3, 17);
			System.out.println(f.get(u3));
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
